package main

import (
	"fmt"
	"time"

	"github.com/Terrdi/workerpool"
	"github.com/valyala/fasthttp"
	"go.uber.org/zap"
)

var logger *zap.Logger

func init() {
	logger, _ = zap.NewProduction()
}

func fastHTTPHandler(ctx *fasthttp.RequestCtx) {
	logger.Info("hello, go module", zap.ByteString("uri", ctx.RequestURI()))
}

func main() {
	fmt.Println("hello, world")

	p := workerpool.New(5, workerpool.WithPreAllocWorkers(false), workerpool.WithBlock(false))

	time.Sleep(time.Second * 2)
	for i := 0; i < 19; i++ {
		err := p.Schedule(func() {
			time.Sleep(time.Second * 3)
		})
		if err != nil {
			println("tasks : ", i, "err: ", err.Error())
		}
	}

	p.Free()

	// fasthttp.ListenAndServe(":8081", fastHTTPHandle)
}
